﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using StoreIGet.Applications.Command;
using StoreIModels;
using StoreRepositorys.Interface;

namespace StoreIGet.Controllers
{
    /// <summary>
    /// 门店
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class StoreController : ControllerBase
    {
        public readonly IMediator _Mediator;
        public readonly IStoreRepository _storeRepository;
        public  StoreController(IMediator mediator, IStoreRepository storeRepository)
        {
            _Mediator = mediator;
            _storeRepository = storeRepository;
        }
        /// <summary>
        /// 门店显示
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<StoreModel>> Get(StoreGetCommand command)
        {
            return await _Mediator.Send(command);
        }
        /// <summary>
        /// 前端门店显示启用的
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> FrontStrore(int sid)
        {
            var res = await _storeRepository.GetAllAsync(x => x.StoreState == "启用"&&(sid==0||x.StoreId==sid));
            return Ok(res);

        }
        /// <summary>
        /// 门店反填
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<StoreModel> Fand(StoreFandCommand command)
        {
            return await _Mediator.Send(command);
        }
        /// <summary>
        /// 配套设施
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<RelationshipStoreModels>> FandRelation(RelationshipStoreCommand command)                               
        {
            return await _Mediator.Send(command);
        }
    }
}
